package com.hnyfkj.jyindustry.biz.chongzhilog.controller;

import java.util.Arrays;


import com.hnyfkj.jyindustry.biz.chongzhilog.dto.ChongzhiLogInsertDto;
import com.hnyfkj.jyindustry.biz.chongzhilog.dto.ChongzhiLogQueryDto;
import com.hnyfkj.jyindustry.biz.chongzhilog.dto.ChongzhiLogUpdateDto;
import com.hnyfkj.jyindustry.biz.chongzhilog.entity.ChongzhiLog;
import com.hnyfkj.jyindustry.biz.chongzhilog.service.ChongzhiLogService;
import com.hnyfkj.jyindustry.common.dto.PageReturnDto;
import com.hnyfkj.jyindustry.common.dto.RespDto;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;

/**
 * 理发店-------充值记录
 *
 * @author zhangzhang
 * @email 15838129129@163.com
 * @date 2021-04-18 16:08:50
 */
@Controller
@RequestMapping("chongzhilog")
public class ChongzhiLogController {
    @Autowired
    private ChongzhiLogService chongzhiLogService;


    /**
     * 列表页面
     */
    @GetMapping("/listPage")
    public String listPage(@RequestParam("id") String id, Model model) {
        model.addAttribute("id", id);
        return "chongzhilog/chongzhilog-table";
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public RespDto<PageReturnDto<ChongzhiLog>> list(@RequestBody ChongzhiLogQueryDto queryDto) {
        return RespDto.succResult(chongzhiLogService.queryPage(queryDto));
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("barbar:chongzhilog:info")
    public RespDto<ChongzhiLog> info(@PathVariable("id") Integer id) {
        ChongzhiLog chongzhiLog = chongzhiLogService.getById(id);
        return RespDto.succResult(chongzhiLog);
    }

    /**
     * 充值  消费   金额
     */
    @RequestMapping("/save")
    @ResponseBody
    public RespDto<String> save(@RequestBody ChongzhiLogInsertDto chongzhiLogInsertDto) {
        return chongzhiLogService.insert(chongzhiLogInsertDto);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("barbar:chongzhilog:update")
    public RespDto<String> update(@RequestBody ChongzhiLogUpdateDto chongzhiLogupdateDto) {
        chongzhiLogService.update(chongzhiLogupdateDto);
        return RespDto.succ();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("barbar:chongzhilog:delete")
    public RespDto<String> delete(@RequestBody Integer[] ids) {
        chongzhiLogService.removeByIds(Arrays.asList(ids));
        return RespDto.succ();
    }

}
